import request from '@/utils/request';
import { SUCCESS_CODE } from '@/utils/types.d';
import type { SysRecordTableListItem } from './types.d';

export async function querySysRecords(
  params: any,
  sort: any,
): Promise<{
  success: boolean;
  total: number;
  data: SysRecordTableListItem[];
}> {
  const res = await request('/api/sys-record/v1.0.0/sys-records', {
    method: 'GET',
    params: {
      data: params,
      sort,
    },
  });
  if (res?.code === SUCCESS_CODE)
    return { success: true, total: res.data.total, data: res.data.data };
  return { success: false, total: 0, data: [] };
}

export async function removeSysRecords(id: string) {
  const res = await request(`/api/sys-record/v1.0.0/sysrecord/${id}`, {
    method: 'DELETE',
  });
  if (res?.code === SUCCESS_CODE) return { success: true, message: '删除成功' };
  return { success: false, message: res?.message || '删除失败' };
}
